<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下拉选项操作</title>
</head>
<body>
    <select id="grade">
        <option id="op1" value="0">--请选择--</option>
        <option value="1">一年级</option>
        <option value="22" selected>二年级</option>
        <option value="3">三年级</option>
    </select>
<button onclick="getIndex()">获取下标值,下标值从0开始</button>
<button onclick="getValue()">获取选中选项的值</button>
<button onclick="selectFun()">设置指定值</button>
</body>
</html>
<script>
    function getIndex() {
        var grade = document.getElementById("grade");
        console.log(grade.selectedIndex);

        var options = grade.options;
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            console.log(option.value+',' + option.text);
        }
        console.log(options.length)
    }

    function getValue() {
        var grade = document.getElementById("grade");
        console.log(grade.value);
    }

    function selectFun() {
        var grade = document.getElementById("grade");
        grade.selectedIndex = 3;
    }
</script>